#include "velocity.h"

Velocity::Velocity(Vectorf * obj)
{
    objectPosition=obj;

    printf("obj : %f", obj->y());
    velocity = new Vectorf(0.0, 0.0, 0.0);
    delta=0.015;    //  15 milliseconde par rafraichissement de l'image
    floor=0.0;
    signe=1;
}

void Velocity::AddAcceleration(Vectorf *vec)
{
    pile.push(vec);
}

void Velocity::Do()
{
    Vectorf * accelerationFinale = new Vectorf(0.0, 0.0, 0.0);

    while(pile.size()!=0)
    {
        *accelerationFinale=*accelerationFinale+(*(pile.top()));
        pile.pop();
    }

    Vectorf vitesseA= (*accelerationFinale*delta);

    *velocity=*velocity+vitesseA;
    *objectPosition= *objectPosition+(*velocity*delta);

    if(objectPosition->y()<floor)
    {
        objectPosition->y(floor);
        *velocity = Vectorf(0.0, 0.0, 0.0);
    }
}


/*
    printf("acceleration max : ");accelerationFinale->Print();
    printf(" vecteur vitesse ;");velocity->Print();
    printf(" position mesh :");objectPosition->Print();*/


